//
//  DepartmentListViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/12/7.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "DepartmentListViewController.h"
#import "DutyDropListModel.h"
#import "StatisticsTableViewCell.h"
#import "InfoListTableViewCell.h"
#import "DepartmentListModel.h"
#import "ManageStrutureModel.h"
#import "AddressSearchModel.h"
#import "PersonInfoDetailViewController.h"
#import "StatisticsListViewController.h"
#import "CenterLabelTableViewCell.h"
#import "PersonSelectViewController.h"

#define getDropList @"getDropList"//获取可选项列表
#define getCheckItemList @"getCheckItemList"//获取考核列表
#define getDepartEmpName @"getDepartEmpName"//模糊查询条件

#define TEXTMESSAGE @"请输入部门名称或员工姓名"//搜索提示语

@interface DepartmentListViewController ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
{
    NSMutableArray *_buttonArr;//保存button
    UITableView *_tableView;//按钮选择列表
    NSInteger _selectButton;//用户当前操作的button
    UITableView *_searchTableView;//搜索结果列表
    AddressSearchModel *_searchListModel;//搜索结果列表model
    UIView *_searchBackView;//搜索view
}

@property (nonatomic,strong)DepartmentListModel *departmentListModel;//汇总信息
@property (nonatomic,strong)NSString *memberNames;
@property (nonatomic,strong)NSMutableArray *summarzingArr;
@property (nonatomic,strong)UIView *tableBackView;
@property (nonatomic,strong)UITextField *searchTextField;
@property (nonatomic,strong)NSArray *dateArr;//时间数组
@property (nonatomic,strong)UIScrollView *backScrollView;//滚动视图
@property (nonatomic,strong)UITableView *infoTableView;//详情tableView
@end

@implementation DepartmentListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setRightBackNavigation];
    [self setLeftBackNavigation];
    [self setNavigationTitle:self.navaTitle?self.navaTitle:@"部门排序"];
    //初始化
    if (self.memberNames==nil) {
        //拼接字符串
        for (int i=0; i<self.manageModel.dataArr.count; i++) {
            ManageStrutureModel *model=self.manageModel.dataArr[i];
            if (i==0) {
                self.memberNames=model.itemId;
            }else{
                self.memberNames=[self.memberNames stringByAppendingString:[NSString stringWithFormat:@",%@",model.itemId]];
            }
        }
    }
    //[self getDropListRequestWithdataSwith:@"2"];
    //默认为本月
    if (self.beginStr==nil||self.endStr==nil) {
        self.beginStr=[LZXHelper getFirstDayInMonth];
        self.endStr=[LZXHelper getLastDayInMonth];
    }
    [self getCheckItemListRequest];
    [self creatView];
    // Do any additional setup after loading the view.
}

- (void)creatView{
    _buttonArr=[NSMutableArray new];
    self.dateArr=@[@"本月",@"上月",@"本季度",@"上季度",@"上半年",@"下半年"];
    //searchView背景
    UIView *searchView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 80)];
    [self.view addSubview:searchView];
    
    _searchTextField=[[UITextField alloc]initWithFrame:CGRectMake(10, 5, IPHONE_WIDTH-20, 30)];        //_spendTextField.color=COLOR_BACKGROUND_GRAY;
    _searchTextField.textAlignment=NSTextAlignmentLeft;
    _searchTextField.delegate=self;
    _searchTextField.font=FONT_14;
    _searchTextField.placeholder=TEXTMESSAGE;
    _searchTextField.backgroundColor=COLOR_BACKGROUND_GRAY;
    //_searchTextField.keyboardType=UIKeyboardTypeNumberPad;
    [searchView addSubview:_searchTextField];
    
    //放大镜
    UIButton *searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.frame=CGRectMake(IPHONE_WIDTH-20-20, 0, 15, 40);
    searchBtn.tag=160;
    [searchBtn setImage:[UIImage imageNamed:@"icon_3_n@2x"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
    [searchView addSubview:searchBtn];
    //分割线
    UILabel *line1=[[UILabel alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, 1)];
    line1.backgroundColor=BACKCOLOR_GRAY;
    [searchView addSubview:line1];
    
    //设置检索按钮
    NSArray *titleArr=@[@"筛选",@"本月",self.itemStr?self.itemStr:@"全部",@"排序"];
    
    for (int i=0; i<titleArr.count; i++) {
        UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(IPHONE_WIDTH/titleArr.count*i, 40, IPHONE_WIDTH/titleArr.count, 40)];
        button.tag=100+i;
        [button setTitle:titleArr[i] forState:UIControlStateNormal];
        //设置图片
        if (i==0) {
            [button setImage:[UIImage imageNamed:@"k_ic_sx@2x"] forState:UIControlStateNormal];
            
        }else if (i==1||i==2){
            [button setImage:[UIImage imageNamed:@"k_ic_xl@2x"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"k_ic_sl@2x"] forState:UIControlStateSelected];
        }else{
            [button setImage:[UIImage imageNamed:@"k_ic_xia@2x"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"k_ic_shang@2x"] forState:UIControlStateSelected];
        }
        //谁知图片和文字的位置
        button.imageEdgeInsets=UIEdgeInsetsMake(10, button.width-20, 10, 0);
        button.titleEdgeInsets=UIEdgeInsetsMake(10, 5, 10, 25);
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //[button setTitleColor:COLOR_SKYBLUE forState:UIControlStateSelected];
        //button.backgroundColor=[UIColor redColor];
        button.titleLabel.font=FONT_14;
        //        [button setTitleColor:COLOR_MIDBLUE forState:UIControlStateSelected];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [searchView addSubview:button];
        [_buttonArr addObject:button];
        
        if (i<titleArr.count-1) {
            UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(IPHONE_WIDTH/titleArr.count*(i+1), 50, 1, 20)];
            line.backgroundColor=BACKCOLOR_GRAY;
            [searchView addSubview:line];
        }
    }
    
    //分割线
    UILabel *line2=[[UILabel alloc]initWithFrame:CGRectMake(0, 79, IPHONE_WIDTH, 1)];
    line2.backgroundColor=BACKCOLOR_GRAY;
    [searchView addSubview:line2];
    if (!self.infoTableView) {
        [self creatInfoTableView];
    }
}



#pragma mark - creatTableView
- (void)creatTableView{
    if (_tableBackView) {
        return;
    }
    CGFloat height=0;
    //计算tableView的高
    if (_selectButton==1) {
        height=self.dateArr.count*44;
    }else{
        height=self.dropListModel.dataArr.count*44;
    }
    
    if (height>IPHONE_HEIGHT-64-80) {
        height=IPHONE_HEIGHT-64-80;
    }
    _tableBackView=[[UIView alloc]initWithFrame:CGRectMake(0, 80, IPHONE_WIDTH, IPHONE_HEIGHT-64-80)];
    [self.view insertSubview:_tableBackView aboveSubview:self.view];
    _tableBackView.backgroundColor=[UIColor clearColor];
    //    [self.view addSubview:_tableBackView];
    
    UIView *alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, _tableBackView.height)];
    alphaView.alpha=0.4;
    alphaView.backgroundColor=[UIColor blackColor];
    [_tableBackView addSubview:alphaView];
    
    //点击手势
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TwoTapGestureRecognizer:)];
    tapGesture.delegate=self;
    [tapGesture setNumberOfTapsRequired:1];
    [tapGesture setNumberOfTouchesRequired:1];
    [alphaView addGestureRecognizer:tapGesture];
    
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH,height) style:UITableViewStylePlain];
    //_myTableView.backgroundColor=[UIColor redColor];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.tag=110;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.showsHorizontalScrollIndicator=NO;
    //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [_tableBackView addSubview:_tableView];
    
    //    [UIView animateWithDuration:0.2 animations:^{
    //        _tableBackView.y=64+80;
    //    }];
    //    self.definesPresentationContext = YES;
}

#pragma mark - 详情列表
- (void)creatInfoTableView{
    if (_infoTableView) {
        return;
    }

    
    _infoTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 80, IPHONE_WIDTH,IPHONE_HEIGHT-64-80) style:UITableViewStylePlain];
    //_myTableView.backgroundColor=[UIColor redColor];
    _infoTableView.delegate=self;
    _infoTableView.dataSource=self;
    _infoTableView.tag=111;
    _infoTableView.bounces=NO;
    _infoTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _infoTableView.showsVerticalScrollIndicator=NO;
    _infoTableView.showsHorizontalScrollIndicator=NO;
    //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [self.view addSubview:_infoTableView];
    
    //    [UIView animateWithDuration:0.2 animations:^{
    //        _tableBackView.y=64+80;
    //    }];
    //    self.definesPresentationContext = YES;
}

#pragma mark- 搜索结果列表
- (void)creatSearchTableView{
    _searchBackView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40)];
    _searchBackView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:_searchBackView];
    
    UIView *alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40)];
    alphaView.alpha=0.4;
    alphaView.backgroundColor=[UIColor blackColor];
    [_searchBackView addSubview:alphaView];
    
    //点击手势
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(OneTapGestureRecognizer:)];
    tapGesture.delegate=self;
    [tapGesture setNumberOfTapsRequired:1];
    [tapGesture setNumberOfTouchesRequired:1];
    [alphaView addGestureRecognizer:tapGesture];
    
    CGFloat height=0;
    //计算tableView的高
    height=_searchListModel.dataArr.count*44;
    
    if (height>_searchBackView.height) {
        height=_searchBackView.height;
    }
    
    _searchTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, height) style:UITableViewStylePlain];
    //_searchTableView.backgroundColor=[UIColor clearColor];
    _searchTableView.delegate=self;
    _searchTableView.dataSource=self;
    _searchTableView.tag=112;
    _searchTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    //[self addTableViewUpdateRefresh:self.tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [_searchBackView addSubview:_searchTableView];
    
}

-(void)OneTapGestureRecognizer:(UIGestureRecognizer*)gr{
    
    if (_searchBackView) {
        [_searchBackView removeFromSuperview];
        _searchBackView=nil;
    }
    
}


-(void)TwoTapGestureRecognizer:(UIGestureRecognizer*)gr{
    
    if (_tableBackView) {
        //        [UIView animateWithDuration:0.2 animations:^{
        //            _tableBackView.y=64+80-(IPHONE_HEIGHT-64-80);
        //        } completion:^(BOOL finished) {
        [_tableBackView removeFromSuperview];
        _tableBackView=nil;
        //        }];
    }
    for (int i=0; i<_buttonArr.count; i++) {
        UIButton *button=_buttonArr[i];
        button.selected=NO;
    }
    
}



#pragma mark -搜索事件
- (void)searchClick{
    [self.view endEditing:YES];
    if (_searchTextField.text.length>0) {
        [self getDepartEmpNameRequestWithSearchtext:_searchTextField.text];
    }
}

- (void)infoButtonClick:(UIButton *)button{
    
}

#pragma mark -检索按钮点击

- (void)buttonClick:(UIButton *)selectButton{
    [self.view endEditing:YES];
    if (selectButton.tag==100) {
        PersonSelectViewController *person=[PersonSelectViewController new];
        __weak DepartmentListViewController *mySelf=self;
        person.myBlock=^(NSString *depOrEmp,NSString *personStr,NSString *departStr){
            mySelf.depOrEmp=[depOrEmp copy];
            mySelf.empIds=[personStr copy];
            mySelf.memberNames=[departStr copy];
            [mySelf getCheckItemListRequest];
        };
        person.manageModel=self.manageModel;
        [self.navigationController pushViewController:person animated:YES];
    }else if (selectButton.tag==103){
        selectButton.selected=!selectButton.selected;
        //根据开关状态 刷新页面
        self.beginStr=[LZXHelper getFirstDayInMonth];
        self.endStr=[LZXHelper getLastDayInMonth];
        [self getCheckItemListRequest];
    }else{
        UIButton *button1=(UIButton *)[selectButton.superview viewWithTag:101];
        UIButton *button2=(UIButton *)[selectButton.superview viewWithTag:102];
        selectButton.selected=!selectButton.selected;
        if (selectButton.selected) {
            _selectButton=selectButton.tag-100;
            //如果没有则创建  如果有则刷新
            if (!_tableBackView) {
                [self creatTableView];
            }else{
                CGFloat height=0;
                //计算tableView的高
                if (_selectButton==1) {
                    height=self.dateArr.count*44;
                }else{
                    height=self.dropListModel.dataArr.count*44;
                }
                //设置tableView的高度
                if (height>IPHONE_HEIGHT-64-80) {
                    height=IPHONE_HEIGHT-64-80;
                }
                _tableView.height=height;
                [_tableView reloadData];
            }
            if (button1==selectButton) {
                button2.selected=NO;
            }else{
                button1.selected=NO;
            }
        }else{
            [_tableBackView removeFromSuperview];
            _tableBackView=nil;
        }
    }
}


#pragma mark -textFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [self addTapGestureRecognizerWithView:self.view];
    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    [self removeTapGestureRecognizerWithView:self.view];
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    if (_searchTextField.text.length>0) {
        //[self getDutyFlowListRequestWithState:@"0"];
    }
    return YES;
}

#pragma mark - TableViewDelagate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView.tag==111) {
        return self.departmentListModel.dataArr.count;
    }else if (tableView.tag==112){
        return _searchListModel.dataArr.count;
    }else{
        if (_selectButton==1) {
            return self.dateArr.count;
        }else if (_selectButton==2){
            return _dropListModel.dataArr.count;
        }
    }
    return 0;
    //return _newsListModel.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.tag==110) {
        //筛选条件
        NSString *cellID=@"StatisticsTableViewCell";
        StatisticsTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[StatisticsTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            //        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        if (_selectButton==1) {
            cell.messageLabel.text=self.dateArr[indexPath.row];
        }
        if (_selectButton==2) {
            DutyDropListModel *model=_dropListModel.dataArr[indexPath.row];
            cell.messageLabel.text=model.keyword;
        }
        return cell;
    }else if(tableView.tag==111){
        //汇总信息
        NSString *cellID=@"InfoListTableViewCell";
        InfoListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[InfoListTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            //        cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.myTitleLabel.width=IPHONE_WIDTH-130-cell.myTitleLabel.y;
            cell.countLabel.x=cell.myTitleLabel.x+cell.myTitleLabel.width;
            cell.countLabel.width=100;
        }
        DepartmentListModel *model=_departmentListModel.dataArr[indexPath.row];
        if (model.belongTo.length>0) {
            cell.myTitleLabel.text=[NSString stringWithFormat:@"%@ (%@)",model.name,model.belongTo];
        }else{
            cell.myTitleLabel.text=model.name;
        }
        if ([self.itemCode isEqualToString:@"ChuQ"]) {
            cell.countLabel.text=[NSString stringWithFormat:@"%@%@%%",self.itemStr,model.result];
        }else if ([self.itemCode isEqualToString:@"QingJ"]||[self.itemCode isEqualToString:@"GongC"]||[self.itemCode isEqualToString:@"TiaoX"]||[self.itemCode isEqualToString:@"JiaB"]){
            cell.countLabel.text=[NSString stringWithFormat:@"%@%@天",self.itemStr,model.result];
        }else{
             cell.countLabel.text=[NSString stringWithFormat:@"%@%@次",self.itemStr,model.result];
        }
        return cell;
    }else{
        //搜索结果列表
        NSString *cellID=@"CenterLabelTableViewCell";
        CenterLabelTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[CenterLabelTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleDefault;
            UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, 43, IPHONE_WIDTH, 1)];
            line.backgroundColor=BACKCOLOR_GRAY;
            [cell.contentView addSubview:line];
        }
        AddressSearchModel *searchModel=_searchListModel.dataArr[indexPath.row];
        cell.myTitle.text=[NSString stringWithFormat:@"%@(%@)",searchModel.respName,[searchModel.isDepart isEqualToString:@"0"]?@"个人":@"部门"];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //计算内容的宽和高
    //    if (_selectButton==2) {
    //        return 44;
    //    }
    if (tableView.tag==111) {
        return 56;
    }
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag==110) {
        //时间段选择
        if (_selectButton==1) {
            //self.dateArr=@[@"本月",@"上月",@"本季度",@"上季度",@"上半年",@"下半年"];
            if ([_dateArr[indexPath.row] isEqualToString:@"本月"]) {
                self.beginStr=[LZXHelper getFirstDayInMonth];
                self.endStr=[LZXHelper getLastDayInMonth];
            }else if ([_dateArr[indexPath.row] isEqualToString:@"上月"]) {
                self.beginStr=[LZXHelper getFirstDayInLastMonth];
                self.endStr=[LZXHelper getLastDayInLastMonth];
            }else if ([_dateArr[indexPath.row] isEqualToString:@"本季度"]) {
                self.beginStr=[LZXHelper getFirstDayWithQuarter];
                self.endStr=[LZXHelper getLastDayWithQuarter];
            }else if ([_dateArr[indexPath.row] isEqualToString:@"上季度"]) {
                self.beginStr=[LZXHelper getFirstDayWithLastQuarter];
                self.endStr=[LZXHelper getLastDayWithLastQuarter];
            }else if ([_dateArr[indexPath.row] isEqualToString:@"上半年"]) {
                self.beginStr=[LZXHelper getFirstDayWithFirstHalfAYear];
                self.endStr=[LZXHelper getLastDayWithFirstHalfAYear];
            }else if ([_dateArr[indexPath.row] isEqualToString:@"下半年"]) {
                self.beginStr=[LZXHelper getFirstDayWithSecondHalfAYear];
                self.endStr=[LZXHelper getLastDayWithSecondHalfAYear];
            }
            [self getCheckItemListRequest];
            //将选择的显示到button上
            UIButton *button=_buttonArr[_selectButton];
            [button setTitle:_dateArr[indexPath.row] forState:UIControlStateNormal];
        }else{
            //信息类型选择
            DutyDropListModel *model=self.dropListModel.dataArr[indexPath.row];
//            //将选择的显示到button上
//            UIButton *button=_buttonArr[_selectButton];
//            [button setTitle:model.keyword forState:UIControlStateNormal];
            self.itemStr=model.keyword;
            self.itemCode=model.keywordId;
            self.beginStr=[LZXHelper getFirstDayInMonth];
            self.endStr=[LZXHelper getLastDayInMonth];
            [self getCheckItemListRequest];
        }
        //点击后开始请求数据 并移除view 重置按钮状态
        [_tableBackView removeFromSuperview];
        _tableBackView=nil;
        for (int i=0; i<_buttonArr.count; i++) {
            UIButton *button=_buttonArr[i];
            if (i==1||i==2) {
                button.selected=NO;
            }
        }
    }else if(tableView.tag==111){
        DepartmentListModel *model=self.departmentListModel.dataArr[indexPath.row];
        //如果是部门
        if ([model.selectType isEqualToString:@"1"]) {
            //根据id 获取下面部门的id
            NSString *memberNames=@"";
            NSString *empIds=nil;
            NSString *depOrEmp=@"";
            NSMutableArray *modelArr=[self.manageModel.dataDict objectForKey:model.ids];
            //拼接字符串
            for (int i=0; i<modelArr.count; i++) {
                ManageStrutureModel *newModel=modelArr[i];
                //部门
                if ([newModel.isDepart isEqualToString:@"1"]) {
                    if (i==0) {
                        memberNames=newModel.itemId;
                    }else{
                        memberNames=[memberNames stringByAppendingString:[NSString stringWithFormat:@",%@",newModel.itemId]];
                    }
                    depOrEmp=@"1";
                }else{
                    //个人取empIds
                    if (i==0) {
                        empIds=newModel.itemId;
                    }else{
                        empIds=[empIds stringByAppendingString:[NSString stringWithFormat:@",%@",newModel.itemId]];
                    }
                    depOrEmp=@"0";
                }
            }
            DepartmentListViewController *listView=[DepartmentListViewController new];
            listView.itemCode=self.itemCode;
            listView.itemStr=self.itemStr;
            listView.memberNames=memberNames;
            listView.empIds=empIds;
            listView.manageModel=self.manageModel;
            listView.dropListModel=self.dropListModel;
            listView.depOrEmp=depOrEmp;
            [self.navigationController pushViewController:listView animated:YES];
        }else{
            //如果是个人
            DepartmentListModel *model=self.departmentListModel.dataArr[indexPath.row];
            PersonInfoDetailViewController *person=[PersonInfoDetailViewController new];
            person.empIds=model.ids;
            person.manageModel=self.manageModel;
            [self.navigationController pushViewController:person animated:YES];
        }

    }else{
        AddressSearchModel *searchModel=_searchListModel.dataArr[indexPath.row];
        //如果是部门
        if ([searchModel.isDepart isEqualToString:@"1"]) {
            StatisticsListViewController *listView=[StatisticsListViewController new];
            listView.navaTitle=searchModel.respName;
            listView.memberNames=self.memberNames;
            [self.navigationController pushViewController:listView animated:YES];
        }else{
            //如果是个人
            PersonInfoDetailViewController *person=[PersonInfoDetailViewController new];
            person.empIds=searchModel.respId;
            person.manageModel=self.manageModel;
            [self.navigationController pushViewController:person animated:YES];
        }
        //搜索的时候移除掉searchBackView
        if (_searchBackView) {
            [_searchBackView removeFromSuperview];
            _searchBackView=nil;
        }
    }
}


//#pragma mark -获取可选项列表
//- (void)getDropListRequestWithdataSwith:(NSString *)dataSwith{
//    NSDictionary *dict=@{
//                         @"dataSwith":dataSwith?dataSwith:@"",
//                         };
//    
//    //   字典转json
//    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
//    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
//    //拼接soap字符串
//    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
//    // __weak AddressBookViewController *mySelf=self;
//    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:[[UIApplication sharedApplication].delegate window]];
//    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getDropList soapBody:soap success:^(id responseObject) {
//        //[LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
//        
//        //解析数据
//        self.dropListModel=[[DutyDropListModel alloc]initWithResponse:responseObject];
//        if ([self.dropListModel.code isEqualToString:@"200"]) {
//
//        }else if([self.dropListModel.code isEqualToString:@"220"]){
//            [LZXHelper postMessageWithText:self.dropListModel.msg View:[[UIApplication sharedApplication].delegate window]];
//        }
//    } failure:^(NSError *error) {
//        //[LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
//    }];
//}

#pragma mark -获取考核列表
- (void)getCheckItemListRequest{
    //获取排序的按钮状态
    UIButton *button=[_buttonArr lastObject];
    //{"beginTime":"2016-12-01","depOrEmp":"1","empIds":"","endTime":"2016-12-31","fid":"","item":"ChuQ","memberNames":"1","orderBy":"1","state":"0"}

    NSDictionary *dict=@{
                         @"beginTime":self.beginStr?self.beginStr:@"",
                         @"endTime":self.endStr?self.endStr:@"",
                         @"depOrEmp":self.depOrEmp?self.depOrEmp:@"1",
                         @"empIds":self.empIds?self.empIds:@"",
                         @"memberNames":_memberNames?_memberNames:@"",
                         @"fid":@"",
                         @"item":self.itemCode?self.itemCode:@"",
                         @"orderBy":button.selected?@"0":@"1",
                         @"state":@"0",
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:[[UIApplication sharedApplication].delegate window]];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getCheckItemList soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
        
        //解析数据
        self.departmentListModel=[[DepartmentListModel alloc]initWithResponse:responseObject];
        if ([self.departmentListModel.code isEqualToString:@"200"]) {
//            //如果有先移除
//            if (!self.backScrollView) {
//                //页面汇总信息按钮
//                [self creatFunctionButtonView];
//            }else{
//                [self refreshInfoButton];
//            }
//            
            if (_infoTableView) {
                [_infoTableView reloadData];
            }
        }else if([self.departmentListModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:self.departmentListModel.msg View:[[UIApplication sharedApplication].delegate window]];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
    }];
}

#pragma mark -模糊查询条件
- (void)getDepartEmpNameRequestWithSearchtext:(NSString *)searchText{
    NSDictionary *dict=@{
                         @"inputValue":searchText,
                         @"isDepartOrEmp":@"2",
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:[[UIApplication sharedApplication].delegate window]];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getDepartEmpName soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
        
        //解析数据
        _searchListModel=[[AddressSearchModel alloc]initWithResponse:responseObject];
        if ([_searchListModel.code isEqualToString:@"200"]) {
            if (!_searchBackView) {
                [self creatSearchTableView];
            }else{
                CGFloat height=0;
                //计算tableView的高
                height=_searchListModel.dataArr.count*44;
                
                if (height>_searchBackView.height) {
                    height=_searchBackView.height;
                }
                _searchTableView.height=height;
                [_searchTableView reloadData];
            }
            if (_searchListModel.dataArr.count==0) {
                //增加提示语
                [self addReminderViewWithFrame:_searchTableView.frame msg:@"没有搜索到该员工！" backView:_searchTableView];
            }else{
                //移除提示语
                [self removeReminderView];
            }
        }else if([_searchListModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_searchListModel.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
